package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressMapper {
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> findList(AddressBook addressBook);

    void save(AddressBook addressBook);
    @Select("select * from address_book where is_default=1 and user_id=#{userId}")
    AddressBook findDefaultAddress(Long userId);
    @Select("select * from address_book where id=#{id}")
    AddressBook findById(Long id);

    void updateAddressBook(AddressBook addressBook);
    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);
    @Update("update address_book set is_default=0 where user_id=#{userId}")
    void setDisDefault(Long userId);
    @Update("update address_book set is_default=1 where id=#{id}")
    void setDefault(Long id);
}
